Public Class limparDados
    Public Sub Limpar(ByVal controlP As Control)
        Dim ctl As Control
        'Limpa os TextBox
        For Each ctl In controlP.Controls
            If TypeOf ctl Is TextBox Then
                DirectCast(ctl, TextBox).Text = String.Empty
                DirectCast(ctl, TextBox).Enabled = True
            ElseIf ctl.Controls.Count > 0 Then
                Limpar(ctl)
            End If
        Next
        'Limpa os ComboBox
        For Each ctl In controlP.Controls
            If TypeOf ctl Is ComboBox Then
                DirectCast(ctl, ComboBox).Text = String.Empty
            ElseIf ctl.Controls.Count > 0 Then
                Limpar(ctl)
            End If
        Next
        'Limpa os RadioButton
        For Each ctl In controlP.Controls
            If TypeOf ctl Is RadioButton Then
                DirectCast(ctl, RadioButton).Checked = False
            ElseIf ctl.Controls.Count > 0 Then
                Limpar(ctl)
            End If
        Next
        'Limpa MaskedTextBox
        For Each ctl In controlP.Controls
            If TypeOf ctl Is MaskedTextBox Then
                DirectCast(ctl, MaskedTextBox).Clear()

            ElseIf ctl.Controls.Count > 0 Then
                Limpar(ctl)
            End If
        Next

        For Each ctl In controlP.Controls
            If TypeOf ctl Is Button Then
                If DirectCast(ctl, Button).Name = "btnAlterar" Or DirectCast(ctl, Button).Name = "btnExcluir" Then

                    DirectCast(ctl, Button).Enabled = False
                Else : DirectCast(ctl, Button).Enabled = True


                End If



            ElseIf ctl.Controls.Count > 0 Then
                Limpar(ctl)
            End If
        Next

        For Each ctl In controlP.Controls
            If TypeOf ctl Is DataGridView Then
                DirectCast(ctl, DataGridView).Columns.Clear()
            ElseIf ctl.Controls.Count > 0 Then
                Limpar(ctl)
            End If
        Next


       


    End Sub

End Class
